
cd "/Users/chuangchen/Library/CloudStorage/OneDrive-UniversityofPittsburgh/Pela project"

use "V-Dem-CY-FullOthers-v14_dta/V-Dem-CY-Full+Others-v14.dta", clear

keep if e_regionpol==2 & year>2002

keep e_gdppc e_peedgini v2xeg_eqdr e_peaveduc v2csantimv e_wbgi_pve v2xpe_exlecon v2xnp_client v2xpas_exclusion v2cacamps v2pepwrsoc v2xpas_religion v2xps_party v2pscohesv v2psplats v2psorgs v2psprbrch v2psprlnks country_name year

bysort year: egen ave_gdp = mean(e_gdppc)
bysort year: gen poor=(e_gdppc<ave_gdp)

bysort year: egen ave_edu = mean(e_peaveduc)
bysort year: gen poor_edu=(e_peaveduc<ave_edu)

bysort year: egen ave_edu_gini = mean(e_peedgini)
bysort year: gen high_edu_gini=(e_peedgini>ave_edu_gini)

bysort year: egen ave_equal = mean(v2xeg_eqdr)
bysort year: gen high_equal=(v2xeg_eqdr<ave_equal)

gen cohesion = (v2pscohesv>0)


egen ave_psi = mean(v2xps_party)
gen low_psi=(v2xps_party<ave_psi)

egen ave_stable = mean(e_wbgi_pve)
gen stable = (e_wbgi_pve>ave_stable)



save "v_dem_LA.dta", replace

******************************************
use "../LASA/Datos/all_countries3_withcontext2.dta", clear
keep pais nestu wave legis ENP c_volatilidad polarization_ID1 polarization_ID2 c_nepp c_polariza c_polarizaw c_gdp c_coherence c_unemployment

bysort pais legis: gen n=_n
keep if n==1

egen vola_ave = median(c_volatilidad)
gen vola_h=(c_volatilidad>vola_ave)

egen ENP_ave = median(ENP)
gen ENP_h=(ENP>ENP_ave)

bysort legis: egen gdp_ave=median(c_gdp)
gen gdp_h=(c_gdp>gdp_ave)

egen enp_ave = median(c_nepp)
gen enp_h=(c_nepp>enp_ave)

egen polar_ave = median(c_polarizaw)
gen polar_h = (c_polarizaw>polar_ave)

rename pais country_name
rename legis year
save "context_pela.dta", replace
******************************************


